#include <iostream>

using std::cout;
using std::endl;

class Single{
private:
    Single()
    {

    }

    ~Single()
    {

    }
public:
    static Single * getInstance(){
        atexit(destroy);
        return _pInstance;
    }

    Single(const Single & rhs)=delete;//这里代表参数是一个Single类型的引用
    Single & operator = (const Single &rhs)=delete;


    void print(){
        cout << "Single::print()" << endl;
    }

private:
    static Single*_pInstance;

    static void destroy(){
        if(_pInstance != nullptr){
            delete _pInstance;
            _pInstance = nullptr;
        }
        return;
    }
    //这里为什么要加Single
    //因为这个参数是给static Single* getInstance(){}用的
    //这个函数需要返回的是一个Single*类型的指针，所以要加Single
};
Single * Single::_pInstance = new Single();

void test(){

    Single * ps1 = Single::getInstance();
    Single * ps2 = Single::getInstance();
    ps1->print();
    ps2->print();
}

int main()
{
    test();
    return 0;
}

